package com.ruoyi.web.controller.organization;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.organization.domain.BaseStorehouse;
import com.ruoyi.organization.service.IBaseStorehouseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库别管理Controller
 * 
 * @author hango
 * @date 2025-10-10
 */
@RestController
@RequestMapping("/organization/storehouse")
public class BaseStorehouseController extends BaseController
{
    @Autowired
    private IBaseStorehouseService baseStorehouseService;

    /**
     * 查询库别管理列表
     */
    @PreAuthorize("@ss.hasPermi('organization:storehouse:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseStorehouse baseStorehouse)
    {
        startPage();
        List<BaseStorehouse> list = baseStorehouseService.selectBaseStorehouseList(baseStorehouse);
        return getDataTable(list);
    }

    /**
     * 导出库别管理列表
     */
    @PreAuthorize("@ss.hasPermi('organization:storehouse:export')")
    @Log(title = "库别管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseStorehouse baseStorehouse)
    {
        List<BaseStorehouse> list = baseStorehouseService.selectBaseStorehouseList(baseStorehouse);
        ExcelUtil<BaseStorehouse> util = new ExcelUtil<BaseStorehouse>(BaseStorehouse.class);
        util.exportExcel(response, list, "库别管理数据");
    }

    /**
     * 获取库别管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('organization:storehouse:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseStorehouseService.selectBaseStorehouseById(id));
    }

    /**
     * 新增库别管理
     */
    @PreAuthorize("@ss.hasPermi('organization:storehouse:add')")
    @Log(title = "库别管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseStorehouse baseStorehouse)
    {
        return toAjax(baseStorehouseService.insertBaseStorehouse(baseStorehouse));
    }

    /**
     * 修改库别管理
     */
    @PreAuthorize("@ss.hasPermi('organization:storehouse:edit')")
    @Log(title = "库别管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseStorehouse baseStorehouse)
    {
        return toAjax(baseStorehouseService.updateBaseStorehouse(baseStorehouse));
    }

    /**
     * 删除库别管理
     */
    @PreAuthorize("@ss.hasPermi('organization:storehouse:remove')")
    @Log(title = "库别管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseStorehouseService.deleteBaseStorehouseByIds(ids));
    }
}
